
/******************************************************************************
*@file  : hal_aes_rom.h
*@brief : Header file of AES HAL module.
******************************************************************************/

#ifndef __HAL_AES_ROM_H__
#define __HAL_AES_ROM_H__

#include "hal.h"

#define AES_KEY_128             0
#define AES_KEY_192             1
#define AES_KEY_256             2

#define AES_SWAP_ENABLE  		1
#define AES_SWAP_DISABLE 		0

#define AES_ENCRYPTION   		1
#define AES_DECRYPTION   		0

#define AES_FAIL                0x00
#define AES_PASS                0xa59ada68

//#define NORFLASH_OPRA_DELAY   36

//typedef struct
//{
//    uint8_t  Command; //must
//    uint8_t  Dummy_bytes; //option
//    uint8_t  Delay; //must
//    uint8_t  Cont_MID;  //must
//    uint32_t Addr;   //must
//    uint32_t Addr_Length; //option  
//    uint32_t Operation_length; //must 
//    uint8_t  *Input_data; //must
//    uint8_t  *Output_data;  //must   
//    uint8_t  *Key_Info;   
//}SPI_Flash_Parameter; 

//typedef uint8_t (*SPI_Nor_Func)(SPI_Flash_Parameter *); 

//extern SPI_Nor_Func *spi_norflash_func; 

//#define  SPI_NORFLASH_FUNC_ADDR     0x3fe0
//#define  SPI_AES_CRYPT_DECRYPT      (spi_norflash_func[7])

void OS_EnterCritical(void);
void OS_ExitCritical(void);

/******************************************************************************
*@brief : function for aes encryption and decryption(ECB mode)
*@param : keyin       : pointer to buffer of key
*@param : key_len     : select length of key(AES_KEY_128/ AES_KEY_192/ AES_KEY_256)
*@param : swap_en     : AES_SWAP_ENABLE, AES_SWAP_DISABLE
*@param : datain      : pointer to buffer of input data
*@param : dataout     : pointer to buffer of output data
*@param : length      : block(128bit) length for aes cryption
*@param : enc         : AES_ENCRYPTION,AES_DECRYPTION
*@return: 0           :AES_FAIL   
          0xa59ada68  :AES_PASS
******************************************************************************/
uint32_t HAL_AES_Crypt_ECB_rom(uint32_t *keyin, uint8_t key_len, uint8_t swap_en,uint32_t *datain, uint32_t *dataout, uint32_t length, uint8_t enc);

/******************************************************************************
*@brief : function for aes encryption and decryption(CBC mode)
*@param : keyin       : pointer to buffer of key
*@param : key_len     : select length of key(AES_KEY_128/ AES_KEY_192/ AES_KEY_256)
*@param : swap_en     : AES_SWAP_ENABLE, AES_SWAP_DISABLE
*@param : datain      : pointer to buffer of input data
*@param : dataout     : pointer to buffer of output data
*@param : length      : block(128bit) length for aes cryption
*@param : enc         : AES_ENCRYPTION,AES_DECRYPTION
*@param : iv          : initial vector for CBC mode
*@return: 0           :AES_FAIL   
          0xa59ada68  :AES_PASS
******************************************************************************/
uint32_t HAL_AES_Crypt_CBC_rom(uint32_t *keyin, uint8_t key_len, uint8_t swap_en,uint32_t *datain, uint32_t *iv, uint32_t *dataout, uint32_t length, uint8_t enc);

#endif